<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<style>
	.ul-form label{width: 50px !important;}
	.ul-form .input-medium{width: 140px !important;}
</style>
<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/list" method="post" class="breadcrumb form-search ">
	<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
	<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
	<sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
	<ul class="ul-form">
		<li class="clearfix"></li>
		<li><label>姓名：</label><form:input path="name" htmlEscape="false" maxlength="50" class="input-medium"/></li>
		<li><label>手机：</label><form:input path="mobile" htmlEscape="false" maxlength="50" class="input-medium"/></li>
		<li class="btns"><a  id="query" href="javascript:void(0)" class="btn btn-primary" > 查询</a>
		<li class="clearfix"></li>
	</ul>
</form:form>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
	<thead><tr><th class="sort-column name">姓名</th><th>手机</th><th>归属部门</th><th >操作</tr></thead>
	<tbody>
	<c:forEach items="${page.list}" var="user">
		<tr>
			<td>${user.loginName}</td>
			<td>${user.mobile}</td>
			<td>${user.office.name}</td>
			<td><button class="btn btn-info add" data-id="${user.id}" data-office="${user.office.name}" data-name="${user.loginName}">添加</button></th></td>
		</tr>
	</c:forEach>
	</tbody>
</table>
<div class="pagination">${page}</div>
<script  type="text/javascript">
	function page(n,s){
		if(n) $("#pageNo").val(n);
		if(s) $("#pageSize").val(s);
		loadUserList();
		return false;
	}
	function loadUserList(){
		var pageNo=$("#pageNo").val();
		var pageSize=$("#pageSize").val();
		var param={};
		param["pageNo"]=pageNo;
		param["pageSize"]=pageSize;
		param["name"]=$("input[name='name']").val()||"";
		param["mobile"]=$("input[name='mobile']").val()||"";
		//加载用户数据
		$("#user_list").load("${ctx}/sys/loan/loan/load/userList",param);
	}
	$(function(){
		function  isManagerReapeat(userId) {
			var isReapeat=false;
			$("#manager_list").find("li").each(function(){
				var id=$(this).data("id");
				if(userId==id){
					isReapeat=true;
					return;
				}
			});
			return isReapeat;
		}
		function bindEvents(){

			$("#query").bind("click",function(){
				loadUserList();
			});
			$(".add").bind("click",function(){
				var userId=$(this).data("id");
				var userName=$(this).data("name");
				var userOffice=$(this).data("office");
				if($("#manager_list").find("li").length==1&&$("#no_data_flag").length==0){
					return;
				}
				if(isManagerReapeat(userId)){
					layer.alert("添加失败，该用户已经添加过",-1)
				}else{
					$li=$("<li data-id='"+userId+"'>"+userName+"("+userOffice+") <i class='icon-remove-sign'></i></li>");
					if($("#no_data_flag").length>0){
						$("#manager_list").html("");
					}
					$("#manager_list").append($li);
					$("#inputForm").append('<input type="hidden" name="managers" id="'+userId+'" value="'+userId+'" >');
				}
			});
		}
		bindEvents();
	});

</script>